package com.itHuangTao.tank.collisions;

import com.almasb.fxgl.dsl.FXGL;
import com.almasb.fxgl.dsl.components.EffectComponent;
import com.almasb.fxgl.dsl.components.HealthIntComponent;
import com.almasb.fxgl.entity.Entity;
import com.almasb.fxgl.physics.CollisionHandler;
import com.itHuangTao.tank.GameType;
import com.itHuangTao.tank.TankApp;
import com.itHuangTao.tank.components.TankComponent;
import com.itHuangTao.tank.effects.ShipEffect;

import static com.almasb.fxgl.dsl.FXGL.spawn;

public class SeaPlayerHandler extends CollisionHandler {
    public SeaPlayerHandler() {
        super(GameType.SEA, GameType.PLAYER);
    }

    //进行碰撞检测
    @Override
    protected void onCollision(Entity sea, Entity player) {
        //判断玩家当前是否有轮船效果
        boolean b = player.getComponent(EffectComponent.class).hasEffect(ShipEffect.class);
        if (!b) {
            spawn("explode", player.getCenter().
                    subtract(50 / 2.0, 50 / 2.0));//在坦克中心爆炸
            player.removeFromWorld();//移除玩家
            //弹出失败场景
            FXGL.<TankApp>getAppCast().gameOver();
        }
    }
}
